/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { Component } from "react";
import { connect } from "dva";
import { Alert } from "antd";
import ServiceTable from "./components/ServiceTable";
import styles from "./style.less";

@connect(({ loading, dispat }) => ({
  dispat,
  getFeeApply: loading.effects["dispat/feeApply"],
}))
class ServiceSettings extends Component {
  constructor(props) {
    super(props);
    this.state = {
      examineType: true,
      new_service_money: 0,
    };
  }

  componentDidMount() {
    this.getDispatchFee();
  }

  getDispatchFee = () => {
    const { dispatch } = this.props;
    dispatch({
      type: "dispat/getDispatchFee",
      payload: {},
    });
  };

  render() {
    const { examineType, new_service_money } = this.state;
    const {
      dispat: { serviceSettings },
    } = this.props;
    const { service_fee, apply_fee, check_status } = serviceSettings;
    // 字段说明
    // check_status == 0：未审核  1：已审核 2：已拒绝
    // service_fee 首次申请 = 0   生效中 ！= 0
    // apply_fee 首次进页面 = 0  上次申请 ！= 0
    // original_fee 首次 = 0
    // first_apply  是否为第一次申请
    // examineType  true：首次进页面
    // examineType ? (service_fee == 0 ? (check_status == 1 ? service_fee : (check_status == 2 ? service_fee : apply_fee)) : (check_status == 0 ? apply_fee : service_fee)) : new_service_money
    const service_money = examineType
      ? service_fee == 0
        ? check_status == 1
          ? service_fee
          : check_status == 2
            ? service_fee
            : apply_fee
        : check_status == 0
          ? apply_fee
          : service_fee
      : new_service_money;
    return (
      <div style={{ paddingTop: 10 }} className={styles.account}>
        <div>
          <Alert
            message={
              <span>
                服务费是加盟商向下属驿站收取的费用。下级驿站入库成功时按票支付，支付的服务费自动进入加盟商的快宝智慧快递管理平台资金账户。每票的服务费金额在加盟商加盟时，由加盟商和快宝驿站商议决定，无法随意改动。
              </span>
            }
            type="warning"
          />
        </div>
        <div style={{ paddingTop: 20 }}>
          <div className={styles.recharge}>
            <div>
              <span className="c-gray">服务费：</span>
              <span className="c-gray">
                <span>{service_fee || 0} 元/票</span>
              </span>
            </div>
          </div>
          <div>
            <ServiceTable />
          </div>
        </div>
      </div>
    );
  }
}

export default ServiceSettings;
